/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.manage.record;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.core.util.KeyValueHelper;
import shop.core.Services;
import shop.core.util.MD5;
import shop.services.manage.record.RecordService;
import shop.services.manage.record.bean.Record;
import shop.core.BaseController;
import shop.core.RequestHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**   
 * @类名称：RecordAction      
 * @创建人：Ltz   
 * @创建时间：2017-10-13 下午16:13:14      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/manage/record/")
public class RecordAction extends BaseController<Record> {
    private static final Logger logger = LoggerFactory.getLogger(RecordAction.class);
    @Autowired
    private RecordService recordService;
    private static final String page_toList = "/manage/record/recordList";
    public RecordService getService() {
        return recordService;
    }

    private RecordAction(){
        super.page_toList = page_toList;
        super.page_toAdd = null;
        super.page_toEdit = null;
    }

    /**
     * 查詢返利记录
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectRecordList")
    @ResponseBody
    public JSONResult selectRecordList(Record record) throws Exception {
        List<Record> recordList = recordService.selectRecordList(record);
        jsonResult = new JSONResult();
        jsonResult.setData(recordList);
        return jsonResult;
    }

    /**
     * 查詢返利明细
     *
     * @param request 请求
     * @param record      对象参数
     * @return 分页数据模型
     */
    @RequestMapping("selectRecordPage")
    @ResponseBody
    public PagerModel selectRecordPage(HttpServletRequest request, Record record) {
        int offset = 0;
        int pageSize = 10;
        int start=Integer.parseInt(request.getParameter("start"));
        int length= Integer.parseInt(request.getParameter("length"));
        if(start>0)
            offset=start;
        if(length>0)
            pageSize=length;
        record.setOffset(offset);
        record.setPageSize(pageSize);
        //查詢返利明细
        PagerModel pager = recordService.selectRecordPage(record);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }
}
